package com.colin.aiyi.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.colin.aiyi.R;
import com.colin.aiyi.adapter.CommnetAdapter;
import com.colin.aiyi.entity.CommentList;
import com.colin.aiyi.eventbus.EventCommentist;
import com.colin.aiyi.presenter.Imp_de.ImpCommentP;
import com.colin.aiyi.presenter.Interface_Derecated.IPresenter;
import com.colin.aiyi.view.ShowMsgUtil;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hl on 2017/6/1.
 */

public class CommentListAc extends BaseActivity {
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.text_banner_left)
    TextView textBannerLeft;
    @BindView(R.id.text_banner_title)
    TextView textBannerTitle;
    @BindView(R.id.text_banner_rigth)
    TextView textBannerRigth;
    @BindView(R.id.text_no_data)
    TextView textNoData;
    private String id = "1";
    private IPresenter iPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_commentlist);
        ButterKnife.bind(this);
        textBannerLeft.setOnClickListener(this);
        textBannerTitle.setText("评论列表");
        if (getIntent() != null) {
            id = getIntent().getStringExtra("id");
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        getContvent(id);
    }

    public void getContvent(String id) {
        iPresenter = new ImpCommentP();
        iPresenter.getTById(id);
        ShowMsgUtil.showLoadingDialog(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void event(EventCommentist sayDatail) {
        ShowMsgUtil.hideLoadingDialog();
        CommentList commentList = sayDatail.getCommentList();
        if (commentList.getCode()!=200||commentList.getData().getCount()<1)
        {
            textNoData.setVisibility(View.VISIBLE);
            return;
        }
        bindView(commentList);
    }

    private void bindView(CommentList commentList) {
        CommnetAdapter headerAndFooterAdapter = new CommnetAdapter(commentList.getData().getItems());
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(headerAndFooterAdapter);
        textNoData.setVisibility(View.GONE);
    }

}
